﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class DiaryproductsDAO:IData<Diaryproducts> 
 	{
		public DiaryproductsDAO(String myconnecString) : base(myconnecString) { }

		public override int OnSubmit(Diaryproducts item, int t) {
			 return connec.ExecuteNonQuery("sp_Diaryproducts", CommandType.StoredProcedure,new SqlParameter("@flag", t),
				 new SqlParameter("@" + Diaryproducts.c_id, item.id), new SqlParameter("@" + Diaryproducts.c_productId, item.productId),
				 new SqlParameter("@" + Diaryproducts.c_price, item.price), new SqlParameter("@" + Diaryproducts.c_lastUpdate, item.lastUpdate),
				 new SqlParameter("@" + Diaryproducts.c_isActive, item.isActive)); 
		}

		public override Diaryproducts GetItem(IDataReader dr)
		{
			Diaryproducts obj = new Diaryproducts();
			obj.id = Convert.ToInt64(dr[Diaryproducts.c_id]);
			obj.productId = Convert.ToInt64(dr[Diaryproducts.c_productId]);
			obj.price = Convert.ToDecimal(dr[Diaryproducts.c_price]);
			obj.lastUpdate = Convert.ToDateTime(dr[Diaryproducts.c_lastUpdate]);
			obj.isActive = Convert.ToInt32(dr[Diaryproducts.c_isActive]);
			return obj;
		}

		public override List<Diaryproducts> GetAll()
		{
			return GetAll("select * from " + Diaryproducts.b_Diaryproducts, CommandType.Text);
		}

		public override Diaryproducts GetItemById(object id)
		{
			throw new NotImplementedException();
		}

	}

 }
